#ifndef __PACKET_HEX_BASE_H__
#define __PACKET_HEX_BASE_H__
#include "PacketBase.h"
namespace controller
{
#pragma pack(1)
    typedef struct
    {
        uint8_t AB;
        uint8_t BA;
        uint8_t hlen;
        uint8_t llen;
        uint32_t D1;
        uint64_t D2;
        uint32_t t;
        uint16_t cmd;
        uint8_t addr, data[PacketBase::BUFFER_MAX - 25];
    } Apacket;
#pragma pack()

    class PacketHexBase : public PacketBase
    {
    private:
        PacketBaseHeader h;
        const uint8_t _packet_reverse[8] = {1, 1, 1, 1, 4, 8, 4, 2}; // 大小端转换(除了数据部分)   ab ba llen hlen d1   d2  ntp  cmd
    public:
        Apacket p;
        PacketHexBase();
        ~PacketHexBase();

        // 接收
        void reset_recv();
        PacketBase *on_get(char *data, int size, void *arg = NULL); // 接收数据的处理

        // 组包
        int to_bytes(char *dataout, void **arg = NULL); // 生成一个字节流的发送包
        int build(uint32_t d1, uint64_t d2, uint32_t t, uint8_t addr, uint16_t cmd, uint16_t datalen, uint8_t *data);

        // 打印
        std::string to_string(std::string arg = ""); // 格式化包的输出
    };
};

#endif